C
C     ..................................................................
C
C     SUBROUTINE DDCAR
C
C     PURPOSE
C	 TO COMPUTE, AT A GIVEN POINT X, AN APPROXIMATION Z TO THE
C	 DERIVATIVE OF AN ANALYTICALLY GIVEN FUNCTION FCT THAT IS 11-
C	 TIMES DIFFERENTIABLE IN A DOMAIN CONTAINING A CLOSED, 2-SIDED
C	 SYMMETRIC INTERVAL OF RADIUS ABSOLUTE H ABOUT X, USING FUNCTION
C	 VALUES ONLY ON THAT CLOSED INTERVAL.
C
C     USAGE
C	 CALL DDCAR(X,H,IH,FCT,Z)
C	 PARAMETER FCT REQUIRES AN EXTERNAL STATEMENT
C
C     DESCRIPTION OF PARAMETERS
C	 X   - THE POINT AT WHICH THE DERIVATIVE IS TO BE COMPUTED
C	       X IS IN DOUBLE PRECISION.
C	 H   - THE NUMBER WHOSE ABSOLUTE VALUE DEFINES THE CLOSED,
C	       SYMMETRIC 2-SIDED INTERVAL ABOUT X (SEE PURPOSE)
C	       H IS IN SINGLE PRECISION
C	 IH  - INPUT PARAMETER (SEE REMARKS AND METHOD)
C	       IH NON-ZERO - THE SUBROUTINE GENERATES THE INTERNAL
C			     VALUE HH
C	       IH    =	 0 - THE INTERNAL VALUE HH IS SET TO ABSOLUTE H
C	 FCT - THE NAME OF THE EXTERNAL DOUBLE PRECISION FUNCTION
C	       SUBPROGRAM THAT WILL GENERATE THE NECESSARY FUNCTION
C	       VALUES.
C	 Z   - RESULTING DERIVATIVE VALUE - DOUBLE PRECISION
C
C     REMARKS
C	 (1)  IF H = 0, THEN THERE IS NO COMPUTATION.
C	 (2)  THE INTERNAL VALUE HH, WHICH IS DETERMINED ACCORDING TO
C	      IH, IS THE MAXIMUM STEP-SIZE USED IN THE COMPUTATION OF
C	      THE CENTRAL DIVIDED DIFFERENCES (SEE METHOD.)  IF IH IS
C	      NON-ZERO, THEN THE SUBROUTINE GENERATES HH ACCORDING TO
C	      CRITERIA THAT BALANCE ROUND-OFF AND TRUNCATION ERROR.  HH
C	      IS ALWAYS LESS THAN OR EQUAL TO ABSOLUTE H IN ABSOLUTE
C	      VALUE, SO THAT ALL COMPUTATION OCCURS WITHIN A RADIUS
C	      ABSOLUTE H OF X.
C
C     SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C	 THE EXTERNAL FUNCTION SUBPROGRAM FCT(T) MUST BE FURNISHED BY
C	 THE USER. FCT(T) IS IN DOUBLE PRECISION
C
C     METHOD
C	 THE COMPUTATION OF Z IS BASED ON RICHARDSON'S AND ROMBERG'S
C	 EXTRAPOLATION METHOD AS APPLIED TO THE SEQUENCE OF CENTRAL
C	 DIVIDED DIFFERENCES ASSOCIATED WITH THE POINT PAIRS
C	 (X-(K*HH)/5,X+(K*HH)/5) K=1,...,5.  (SEE FILLIPI, S. AND
C	 ENGELS, H., ALTES UND NEUES ZUR NUMERISCHEN DIFFERENTIATION,
C	 ELECTRONISCHE DATENVERARBEITUNG, ISS. 2 (1966), PP. 57-65.)
C
C     ..................................................................
C
      SUBROUTINE DDCAR(X,H,IH,FCT,Z)
C
C
      DIMENSION AUX(5)
      DOUBLE PRECISION X,FCT,Z,AUX,A,B,C,DH,HH
C
C	 NO ACTION IN CASE OF ZERO INTERVAL LENGTH
      IF(H)1,17,1
C
C	 GENERATE STEPSIZE HH FOR DIVIDED DIFFERENCES
    1 C=ABS(H)
      IF(IH)2,9,2
    2 HH=.5D-2
      IF(C-HH)3,4,4
    3 HH=C
    4 A=FCT(X+HH)
      B=FCT(X-HH)
      Z=DABS((A-B)/(HH+HH))
      A=.5D0*DABS(A+B)
      HH=.5D-2
      IF(A-1.D0)6,6,5
    5 HH=HH*A
    6 IF(Z-1.D0)8,8,7
    7 HH=HH/Z
    8 IF(HH-C)10,10,9
    9 HH=C
C
C	 INITIALIZE DIFFERENTIATION LOOP
   10 Z=(FCT(X+HH)-FCT(X-HH))/(HH+HH)
      J=5
      JJ=J-1
      AUX(J)=Z
      DH=HH/DFLOAT(J)
      DZ=1.E38
C
C	 START DIFFERENTIATION LOOP
   11 J=J-1
      C=J
      HH=C*DH
      AUX(J)=(FCT(X+HH)-FCT(X-HH))/(HH+HH)
C
C	 INITIALIZE EXTRAPOLATION LOOP
      D2=1.E38
      B=0.D0
      A=1.D0/C
C
C        START EXTRAPOLATION LOOP
      DO 12 I=J,JJ
      D1=D2
      B=B+A
      HH=(AUX(I)-AUX(I+1))/(B*(2.D0+B))
      AUX(I+1)=AUX(I)+HH
C
C        TEST ON OSCILLATING INCREMENTS
      D2=DABS(HH)
      IF(D2-D1)12,13,13
   12 CONTINUE
C        END OF EXTRAPOLATION LOOP
C
C        UPDATE RESULT VALUE Z
      I=JJ+1
      GO TO 14
   13 D2=D1
      JJ=I
   14 IF(D2-DZ)15,16,16
   15 DZ=D2
      Z=AUX(I)
   16 IF(J-1)17,17,11
C        END OF DIFFERENTIATION LOOP
C
   17 RETURN
      END
      END OF EXTRAPOLATION LOOP
